package test;

import helpClass.TimeProcesser;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

public class UUIDGen {
	
	private static int genNum = 50000;
	private static int genLength = 16;
	private static String filePath = "C:/Users/Administrator/Desktop/cdkey/cdkey_Gen.txt";
	
	private static String[] testData = {"abcdefg123456781", "abcdefg123456782", "abcdefg123456783", "abcdefg123456784", "abcdefg123456785", "abcdefg123456786"};
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int begin = TimeProcesser.getUnixTime();
		Set<String> genSet = new HashSet<String>();
		while (genSet.size() < genNum) {
			genSet.add(UUID.randomUUID().toString().replaceAll("-", "").substring(0, genLength).toUpperCase());
		}
//		print(genSet);
		System.out.println("time=" + (TimeProcesser.getUnixTime() - begin));
	}
	
	public static void print(Set<String> genSet) {
		try {
			File file = new File(filePath);
			OutputStream out = new FileOutputStream(file);
			for (String one : genSet) {
				out.write(one.getBytes());
				out.write("\n".getBytes());
				System.out.println(one);
			}
			for (String one : testData) {
				out.write(one.getBytes());
				out.write("\n".getBytes());
				System.out.println(one);
			}
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
